# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libnfs
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.0.2
pkgrel=1
pkgdesc="Client library for accessing NFS shares over a network (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/sahlberg/libnfs/"
license=('BSD' 'GPL3' 'LGPL2.1')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/sahlberg/libnfs/archive/${_realname}-${pkgver}.tar.gz"
        2.0.0-win32.patch
        2.0.0-no-unefined.patch)
sha256sums=('637e56643b19da9fba98f06847788c4dad308b723156a64748041035dcdf9bd3'
            '42431022a0dac3384501c0e1f84490df93e6d4e7870dc87c00371b93222f6992'
            '9590fb375cdac86fa9cc03c7dca448428c2fd0b045868b5790e6487795cedb26')

prepare() {
  cd ${_realname}-${_realname}-${pkgver}

  patch -p1 -i ${srcdir}/2.0.0-win32.patch
  patch -p1 -i ${srcdir}/2.0.0-no-unefined.patch

  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  mkdir ${srcdir}/build-${MSYSTEM} && cd ${srcdir}/build-${MSYSTEM}

  ../${_realname}-${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --enable-utils

  make
}

package() {
  cd build-${MSYSTEM}

  make DESTDIR="${pkgdir}" install

  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENCE-BSD.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENCE-BSD.txt
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENCE-GPL-3.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENCE-GPL-3.txt
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENCE-LGPL-2.1.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENCE-LGPL-2.1.txt
}
